<?php
/**
 * Created by PhpStorm.
 * User: LG
 * Date: 2018/8/2
 * 数据库的操作 三方库Medoo的使用
 */
header("content-type:text/html;charset=utf-8");         //设置编码

require_once 'Medoo.php';
require_once 'Contact.php';

select(); //查询

insert(); //插入

//update(); //修改

//deleted(); //删除


/**
 * 查询
 */
function select()
{
    global $database;

    // 查询数据示例
    $datas = $database->select("account", [
        "user_name",
        "email",
        "age",
        "lang"

    ], [
        "age[>]" => 12
    ]);

    foreach ($datas as $data) {
        $result0 = array(
            'user_name' => urlencode($data["user_name"]),
            'email' => urlencode($data["email"]),
            'age' => urlencode($data["age"]),
            'age' => urlencode($data["lang"])
        );
        $result1 = array(
            'code' => urlencode(200),
            'msg' => urlencode('查询成功'),
            'data' => $result0
        );
        echo urldecode(json_encode($result1));
    }
}


/**
 * 插入
 */
function insert()
{
    global $database;
    $database->insert('account', [
        'user_name' => '刘国',
        'email' => '1421880926@qq.com',
        'age' => 51,
        'lang' => '爱好吃饭，睡觉，打豆豆'
    ]);
}


/**
 * 更新
 */
function update()
{
    global $database;
    $database->update("account", [
        "user_name" => "张杰",
        "age" => "22"
    ], [
        "age[<]" => 26
    ]);

}


/**
 * 删除
 */
function deleted()
{
    global $database;
    $database->delete("account", [
        "AND" => [
        "age[<]" => 50
    ]
]);

}



